package service

import (
	"gin/common"
	"gin/model"
	"github.com/go-ego/gpy"
	"strings"
)

func CreateStory(data model.Story) (model.Story, error) {
	if data.Code == "" {
		data.Code = strings.Join(gpy.LazyConvert(data.Name, nil), "")
	}
	_, err := data.Insert()
	return data, err
}

func FindStory(Param common.SelectQueryParam) (resData model.Story, err error) {
	var logModel model.Story
	resData, err = logModel.Find(Param)
	return
}

func SelectStory(Param *common.SelectQueryParam) (total int64, resData []model.Story, err error) {
	var logModel model.Story

	total, resData, err = logModel.Select(Param)

	return
}

func UpdateStory(Data model.Story) (model.Story, error) {
	return Data.Update(Data)
}

func DeleteStory(param *common.Filter) {
	var logModel model.Story
	logModel.DeleteByFilter(param)
	return
}
